% main svd
clear all;
N = 10000; % number of transmit bits N 为Tx的倍数
snr_dB = 0:15; % Eb/No values
Tx = 2;
Rx = 2;
for snr_count = 1 : length(snr_dB)
    
    error = 0;

    for ii = 1 : N
        snr_val = sqrt(2)*(10^(-snr_dB(snr_count)/10));

        src = round(rand(Tx, 1));
        smod = 2 * src - 1;

        n = (1/sqrt(2)) * (randn(Tx, 1) + j * randn(Tx, 1));
        H = (1/sqrt(2)) * (randn(Rx, Tx) + j * randn(Rx, Tx));

        out = mimo_svd(H, smod, n*(snr_val^2));
        error = error + length(find(out ~= smod));
    end
    

    BER_all(snr_count) = error/(N * Tx);
end

semilogy(snr_dB, BER_all);

    
